#include<bits/stdc++.h>

using namespace std;
int a[1000];
int book[1000];
int n = 4;

void dfs(int k) {
    if (k >= 3) {
        copy(a, a + n, ostream_iterator<int>(cout, " "));
        cout << endl;
        return;
    }
    for (int i = 1; i <= n; i++) {
        if (book[i] == 1)continue;
        if (k >= 1 && i < a[k - 1])continue;
        book[i] = 1;
        a[k] = i;
        dfs(k + 1);
        book[i] = 0;
    }


}

int main() {
    dfs(0);
    return 0;
}
